package com.tanhua.manage.controller;

import com.tanhua.manage.service.PublishAuditService;
import com.tanhua.manage.vo.Pager;
import com.tanhua.manage.vo.PublishItemsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 内容审核
 *
 * @author guzi
 * @date 2021/1/12
 */
@RestController
@RequestMapping("/manage/messages")
public class PublishAuditController {

    @Autowired
    private PublishAuditService publishAuditService;

    /**
     * 查询动态审核列表
     * <p>
     * Integer pagesize, //页尺寸
     * Integer page,    //页数
     * String sortProp, //排序字段
     * String sortOrder, //ascending 升序 descending 降序
     * String id, //消息id
     * String sd, //开始时间
     * String ed, //结束时间
     * String uid, //用户ID
     * String state //审核状态
     *  defaultValue = "10"
     * @return
     */
    @GetMapping
    public ResponseEntity<Pager> getPublishAuditList(@RequestParam("pagesize") Integer pagesize,//页面大小
                                                     @RequestParam("page") Integer page,    //页数
                                                     @RequestParam("sortProp") String sortProp, //排序字段
                                                     @RequestParam("sortOrder") String sortOrder, //ascending 升序 descending 降序
                                                     @RequestParam("id") String id, //消息id
                                                     @RequestParam("sd") String sd, //开始时间
                                                     @RequestParam("ed") String ed, //结束时间
                                                     //@RequestParam(value = "uid") Integer uid, //用户ID
                                                     @RequestParam("state") String state //审核状态
    ) {
        Map<String, Object> param = new HashMap<>(7);
        param.put("pagesize", pagesize);
        param.put("page", page);
        param.put("sortProp", sortProp);
        param.put("sortOrder", sortOrder);
        param.put("id", id);
        param.put("sd", sd);
        param.put("ed", ed);
        //param.put("uid", uid);
        param.put("state", state);

        try {
            Pager<PublishItemsVo> publishAuditList = this.publishAuditService.getPublishAuditList(param);
            return ResponseEntity.ok(publishAuditList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 动态 pass
     *
     * @param publishIds
     * @return
     */
    @PostMapping("pass")
    public ResponseEntity<String> publishPass(@RequestBody String[] publishIds) {
        try {
            String result = this.publishAuditService.publishPass(publishIds);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 动态 reject
     *
     * @param publishIds
     * @return
     */
    @PostMapping("reject")
    public ResponseEntity<String> publishReject(@RequestBody String[] publishIds) {
        try {
            String result = this.publishAuditService.publishReject(publishIds);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 动态 revocation
     *
     * @param publishIds
     * @return
     */
    @PostMapping("revocation")
    public ResponseEntity<String> publishRevocation(@RequestBody String[] publishIds) {
        try {
            String result = this.publishAuditService.publishRevocation(publishIds);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
